<template>
  <div class="emotion-care" :class="{ active: showEmotionCare }">
    <div class="care-overlay" @click="closeCare"></div>
    <div class="care-content">
      <div class="care-header">
        <div class="avatar">
          <div class="avatar-img">
            <div class="emotion-icon" :class="currentEmotion">
              <el-icon v-if="currentEmotion === 'anxious'"><Warning /></el-icon>
              <el-icon v-if="currentEmotion === 'sad'"><Cold /></el-icon>
              <el-icon v-if="currentEmotion === 'stressed'"><Sunny /></el-icon>
            </div>
          </div>
        </div>
        <div class="header-text">
          <h3>{{ emotionTitle }}</h3>
          <p>{{ emotionSubtitle }}</p>
        </div>
        <el-button class="close-btn" @click="closeCare" circle>
          <el-icon><Close /></el-icon>
        </el-button>
      </div>
      
      <div class="care-body">
        <div class="message-section">
          <div class="message-bubble">
            {{ emotionMessage }}
          </div>
        </div>
        
        <div class="suggestions">
          <h4>放松建议</h4>
          <div class="suggestion-list">
            <div 
              v-for="(suggestion, index) in emotionSuggestions" 
              :key="index"
              class="suggestion-item"
            >
              <div class="suggestion-icon">
                <el-icon><Check /></el-icon>
              </div>
              <div class="suggestion-text">{{ suggestion }}</div>
            </div>
          </div>
        </div>
        
        <div class="support-options">
          <h4>心理支持</h4>
          <div class="support-buttons">
            <el-button @click="contactCounselor">
              <el-icon><Service /></el-icon>
              联系心理咨询师
            </el-button>
            <el-button @click="playRelaxation">
              <el-icon><VideoPlay /></el-icon>
              放松训练
            </el-button>
            <el-button @click="breathingExercise">
              <el-icon><WindPower /></el-icon>
              呼吸练习
            </el-button>
          </div>
        </div>
      </div>
      
      <div class="care-footer">
        <el-checkbox v-model="dontShowAgain">不再显示</el-checkbox>
        <el-button type="primary" @click="closeCare">我知道了</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { 
  ElButton, 
  ElIcon, 
  ElCheckbox 
} from 'element-plus'
import { 
  Warning, 
  Cold, 
  Sunny, 
  Close, 
  Check, 
  Service, 
  VideoPlay, 
  WindPower 
} from '@element-plus/icons-vue'

// 情绪状态
const showEmotionCare = ref(false)
const currentEmotion = ref('anxious') // anxious, sad, stressed
const dontShowAgain = ref(false)

// 情绪内容配置
const emotionConfig = {
  anxious: {
    title: '感觉您有些焦虑',
    subtitle: '深呼吸，让我们一起缓解您的紧张情绪',
    message: '在就医过程中感到焦虑是很正常的，很多人都会有这样的感受。请记住，我们的医疗团队会为您提供最好的照顾。您可以尝试以下方法来放松自己。',
    suggestions: [
      '进行深呼吸练习，慢慢吸气4秒，屏息4秒，呼气4秒',
      '专注于当下，感受自己的身体和周围环境',
      '告诉自己："我正在接受专业的医疗帮助"',
      '闭上眼睛，想象一个让您感到安全和平静的地方'
    ]
  },
  sad: {
    title: '感觉您有些低落',
    subtitle: '您的感受是可以理解的，我们在这里陪伴您',
    message: '生病或担心健康问题时感到难过是人之常情。请记住，您并不孤单，我们整个医疗团队都会支持您。让我们一起面对这些挑战。',
    suggestions: [
      '允许自己感受这些情绪，不要强迫自己"振作起来"',
      '与信任的朋友或家人分享您的感受',
      '写下您的想法和感受，有助于整理思绪',
      '做一些平时能带给您安慰的小事'
    ]
  },
  stressed: {
    title: '感觉您压力很大',
    subtitle: '让我们一起找到缓解压力的方法',
    message: '面对健康问题时感到压力是完全正常的反应。请记住，压力是可以管理的，我们有一些有效的方法可以帮助您放松和应对。',
    suggestions: [
      '尝试渐进式肌肉放松法，从脚趾开始到头部',
      '听一些舒缓的音乐或自然声音',
      '进行短暂的散步，接触自然环境',
      '专注于解决当前最重要的问题，把大问题分解成小步骤'
    ]
  }
}

// 计算属性
const emotionTitle = computed(() => {
  return emotionConfig[currentEmotion.value]?.title || '情绪关怀'
})

const emotionSubtitle = computed(() => {
  return emotionConfig[currentEmotion.value]?.subtitle || ''
})

const emotionMessage = computed(() => {
  return emotionConfig[currentEmotion.value]?.message || ''
})

const emotionSuggestions = computed(() => {
  return emotionConfig[currentEmotion.value]?.suggestions || []
})

// 方法
const showCare = (emotion) => {
  currentEmotion.value = emotion
  showEmotionCare.value = true
}

const closeCare = () => {
  showEmotionCare.value = false
  // 如果选择了"不再显示"，可以保存到本地存储
  if (dontShowAgain.value) {
    localStorage.setItem('emotionCareDisabled', 'true')
  }
}

const contactCounselor = () => {
  console.log('联系心理咨询师')
  // 这里可以打开联系心理咨询师的界面
}

const playRelaxation = () => {
  console.log('播放放松训练')
  // 这里可以播放放松训练音频或视频
}

const breathingExercise = () => {
  console.log('开始呼吸练习')
  // 这里可以打开呼吸练习引导界面
}

// 暴露方法给父组件
defineExpose({
  showCare
})
</script>

<style scoped>
.emotion-care {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  visibility: hidden;
  opacity: 0;
  transition: all 0.3s ease;
}

.emotion-care.active {
  visibility: visible;
  opacity: 1;
}

.care-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
}

.care-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 600px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.care-header {
  display: flex;
  align-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #409eff, #64b5f6);
  color: white;
}

.avatar {
  margin-right: 16px;
}

.avatar-img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.emotion-icon {
  font-size: 28px;
}

.emotion-icon.anxious {
  color: #ffd700;
}

.emotion-icon.sad {
  color: #4fc3f7;
}

.emotion-icon.stressed {
  color: #81c784;
}

.header-text h3 {
  margin: 0 0 4px 0;
  font-size: 20px;
}

.header-text p {
  margin: 0;
  opacity: 0.9;
}

.close-btn {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.2) !important;
  border: none !important;
  color: white !important;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.3) !important;
}

.care-body {
  padding: 20px;
  max-height: 60vh;
  overflow-y: auto;
}

.message-section {
  margin-bottom: 24px;
}

.message-bubble {
  background: #f0f8ff;
  border-radius: 12px;
  padding: 16px;
  font-size: 15px;
  line-height: 1.6;
  position: relative;
}

.message-bubble::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 30px;
  border-width: 10px 10px 0;
  border-style: solid;
  border-color: #f0f8ff transparent;
}

.suggestions h4,
.support-options h4 {
  margin-top: 0;
  margin-bottom: 16px;
  color: #333;
}

.suggestion-list {
  margin-bottom: 24px;
}

.suggestion-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 12px;
}

.suggestion-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #409eff;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  margin-right: 12px;
  flex-shrink: 0;
  margin-top: 2px;
}

.support-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.support-buttons .el-button {
  justify-content: flex-start;
}

.care-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-top: 1px solid #eee;
}
</style>